// 给定一个字符串，
// 你需要反转字符串中每个单词的字符顺序，
// 同时仍保留空格和单词的初始顺序。

#include <stdio.h>

void swap(char *a, char *b)
{
    int temp = (*a - *b);
    *a -= temp;
    *b += temp;
}
void reverseString(char *s, int a, int sSize)
{
    for (int i = a; i <= a + (sSize - 1) / 2; i++)
    {
        swap(&s[i], &s[2 * a + sSize - 1 - i]);
    }
}

char *reverseWords(char *s)
{
    int i = 0;
    int j = 1;
    while (s[i] != '\0')
    {
        if (s[i] != ' ')
        {

            while (s[i + j] != ' ' && s[i + j] != '\0')
            {
                j++;
            }
            if (j > 1)
            {
                reverseString(s, i, j);
            }
        }
        i += j;
        j = 1;
    }

    return s;
}

int main()
{
    char s[] = " asdf ";
    char *str = reverseWords(s);
    printf("%s", str);
}